package com.gxa.modules.app.outpatient.book.controller;

import com.gxa.common.utils.Result;
import com.gxa.modules.model.dto.DoctorDTO;
import com.gxa.modules.model.dto.ParkDTO;
import com.gxa.modules.model.dto.TimeAndNumDTO;
import com.gxa.modules.model.entity.hospital.Department;
import com.gxa.modules.model.vo.BookInfoVO;
import com.gxa.modules.model.vo.ScheduleVO;
import com.gxa.modules.pc.hospital.service.DepartmentService;
import com.gxa.modules.pc.order.service.BookRegisterService;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

/**
 * @Description:
 * @Author: zhuiyi
 * @CreatTime: 2022/11/14 8:29
 **/
@RestController
@Api(tags = "APP端--门诊服务--预约挂号")
public class AppBookContrller {

    @Autowired
    private DepartmentService departmentService;
    //调用 获取用户信息

    @Autowired
    private BookRegisterService bookRegisterService;


    //获取大科室名称
    @ApiOperation("获取大科室名称")
    @GetMapping("/app/bigNames")
    public Result getAppGigNames(){
        Set<String> bigNames = departmentService.getBigNames();
        return new Result().ok(bigNames);
    }

    //获取院区列表
    @ApiOperation("获取院区列表")
    @GetMapping("/app/partList")
    public Result getPartList(){
        List<ParkDTO> partList = departmentService.getPartList();
        return new Result().ok(partList);
    }

    //获取科室信息
    @ApiOperation("获取科室信息")
    @GetMapping("/app/departments")
//    @ApiParam(name = "partId",value = "园区id",required = true)
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query",name = "partId",value = "园区id",dataType = "int"),
            @ApiImplicitParam(paramType = "query",name = "bigName",value = "大科室名字",dataType = "String"),
    })
    public Result getAppDepartments( @RequestParam(defaultValue = "1") Integer partId,@RequestParam(defaultValue = "内科") String bigName){
        List<Department> deparments = departmentService.getDeparments(partId,bigName);
        return new Result().ok(deparments);
    }



    //app 获取 医生信息
    @ApiOperation("获取科室医生信息")
    @GetMapping("/app/doctors")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query",name = "departmentName",value = "科室名称",dataType = "String"),
            @ApiImplicitParam(paramType = "query",name = "day",value = "哪一天？",dataType = "String"),
    })
    public Result getAppDepartmentsDoctors( @RequestParam(defaultValue = "骨科") String departmentName,@RequestParam(defaultValue = "2022-11-14") String day){
        Result doctors = departmentService.getDoctors(departmentName, day);
        return doctors;
    }
    //app 点击对应医生 显示对应排班的时间点 以及 剩余 预约数量
    @ApiOperation("获取排班时间点信息：剩余预约数量")
    @GetMapping("/app/timeAndNum")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query",name = "doctorName",value = "医生名字",dataType = "String" ,required = true),
            @ApiImplicitParam(paramType = "query",name = "workDate",value = "预约哪一天",dataType = "String",required = true),
    })
    public Result getAppTimeAndNum(@RequestParam @ApiIgnore HashMap<String,Object> params){
        Map<String,Object> dto = this.bookRegisterService.getTimeAndNum(params);
        return new Result().ok(dto);
    }
    //app 生成 预约信息
    @ApiOperation("生成预约信息")
    @GetMapping("/app/bookinfo")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query",name = "departmentName",value = "科室名称",dataType = "String",required = true),
            @ApiImplicitParam(paramType = "query",name = "workDate",value = "院区id",dataType = "String",required = true),
            @ApiImplicitParam(paramType = "query",name = "parkId",value = "院区id",dataType = "int",required = true),
            @ApiImplicitParam(paramType = "query",name = "doctorName",value = "医生姓名",dataType = "String",required = true),

            @ApiImplicitParam(paramType = "query",name = "time",value = "候诊时间 例如：9:30 字符串",dataType = "String",required = true),
            @ApiImplicitParam(paramType = "query",name = "username",value = "当前登录用户名",dataType = "String",required = true),
            @ApiImplicitParam(paramType = "query",name = "idCard",value = "用户身份证",dataType = "String",required = true),
    })
    public Result generateBookInfo( @RequestParam @ApiIgnore HashMap<String,Object> paramsMap){
        BookInfoVO bookInfo = bookRegisterService.getBookInfo(paramsMap);
        return new Result().ok(bookInfo);

    }

    //app 获取当周日期
    @ApiOperation("获取当周日期")
    @GetMapping("/app/week")
    public Result getWeek(){
        Map<String, Object> weekDays = this.bookRegisterService.getWeekDays();
        return new Result().ok(weekDays);
    }
    //app 候诊查询
//    @ApiOperation("候诊查询")
//    @GetMapping("/app/wait")
//    public Result wait(){
////        Map<String, Object> weekDays = this.bookRegisterService.getwait();
//        return new Result().ok(weekDays);
//    }

    //app 获取该医生所有排班
    @ApiOperation("根据医生id获取大于等于今天的该医生的排班信息")
    @GetMapping("/app/doctorSchedules")
    public Result getWeek(@ApiParam(value = "医生id") @RequestParam("doctorId") String doctorId){
        List<ScheduleVO> schedules = this.departmentService.getDoctorSchedule(doctorId);
        return new Result().ok(schedules);
    }


}
